package com.shawn.example.mvvmdemo.login.repository

import com.jetpack.mvvm.lib.base.constants.Constants
import com.jetpack.mvvm.lib.base.resp.HttpResult
import com.jetpack.mvvm.lib.common.ext.Prefs
import com.jetpack.mvvm.lib.net.module.HttpApiResult
import com.shawn.example.mvvmdemo.login.model.LoginModel
import dagger.hilt.android.scopes.ActivityRetainedScoped
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@ActivityRetainedScoped
class RegisterLoginRepository @Inject constructor() {
    companion object {
        private const val TAG = "RegisterLoginRepository"
    }

    @Inject
    lateinit var remoteRepository: RegisterLoginRemoteRepository


    fun loginWanAndroid(
        username: String,
        password: String
    ): Flow<HttpResult<LoginModel>> {
        return remoteRepository.loginWanAndroid(username, password)
    }

    suspend fun loginWanApp(
        username: String,
        password: String
    ): HttpApiResult<LoginModel> {
        return remoteRepository.loginWanApp(username, password)
    }

    fun cacheLoginUserData(model: LoginModel) {
        model.id ?: return
        Prefs.putString(Constants.USER_NAME, model.username ?: "")
        Prefs.putString(Constants.USER_ID, model.id.toString())
    }
}